package com.zbkj.crmeb.merchant.admin.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.pdd.request.SyPddGoodsAddRequest;
import com.zbkj.crmeb.pdd.service.PddAccountService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;


/**
 * 拼多多商品操作
 * @author daigb
 * @date:  2022-11-28 15:22
 */
@RestController
@RequestMapping("api/admin/mer/pdd/product")
@Api(tags = "拼多多商品操作")
public class MerPddProductController extends AdminBaseController {
	@Autowired
    private PddAccountService pddAccountService;

    @ApiOperation(value = "查询店铺可上架商品类目")
    @GetMapping("/goodsAuthorizationCats")
    public CommonResult<Object> goodsAuthorizationCats(@ApiParam(value = "分类id", required = true) @RequestParam(value = "cateId") Long cateId, HttpServletRequest request) throws Exception{
    	return CommonResult.success(pddAccountService.goodsAuthorizationCats(getMerId(request), cateId));
    }
    
    /**
     * cateId: 必须为三级类目
     * goods_service_rule.goods_service_rule_map.goods_type_list: 判断商品发货地
     * @author daigb
     * @date:  2022-11-28 16:01
     */
    @ApiOperation(value = "查询类目发布规则")
    @GetMapping("/goodsCatRule")
    public CommonResult<Object> goodsCatRule(@ApiParam(value = "分类id", required = true) @RequestParam(value = "cateId") Long cateId, HttpServletRequest request) throws Exception{
    	return CommonResult.success(pddAccountService.goodsCatRule(getMerId(request), cateId));
    }
    
    @ApiOperation(value = "商品国家获取(仅在goods_type为2、3时, 其余传0)")
    @GetMapping("/goodsCountry")
    public CommonResult<Object> goodsCountry(HttpServletRequest request) throws Exception{
    	return CommonResult.success(pddAccountService.goodsCountry(getMerId(request)));
    }
    
    @ApiOperation(value = "运费模板获取")
    @GetMapping("/goodsLogisticsTemplate")
    public CommonResult<Object> goodsLogisticsTemplate(HttpServletRequest request) throws Exception{
    	return CommonResult.success(pddAccountService.goodsLogisticsTemplate(getMerId(request)));
    }
    
    @ApiOperation(value = "类目规则属性获取")
    @GetMapping("/goodsSpec")
    public CommonResult<Object> goodsSpec(@ApiParam(value = "分类id", required = true) @RequestParam(value = "cateId") Long cateId, HttpServletRequest request) throws Exception{
    	return CommonResult.success(pddAccountService.goodsSpec(cateId, getMerId(request)));
    }
    
    @ApiOperation(value = "新增商家规则")
    @GetMapping("/goodsSpecId")
    public CommonResult<Object> goodsSpecIdGet(@ApiParam(value = "规格id", required = true) @RequestParam(value = "specId") Long specId, @ApiParam(value = "规格名", required = true) @RequestParam(value = "specName") String specName, HttpServletRequest request) throws Exception{
    	return CommonResult.success(pddAccountService.goodsSpecId(specId, specName, getMerId(request)));
    }
    
    /**
     * warehouse: 在goodsType=3时传入
     * 宁波保税仓、杭州保税仓、广州保税仓、深圳保税仓、重庆保税仓、郑州保税仓、福建保税仓、天津保税仓、上海保税仓、银川保税仓、成都保税仓
     * twoPiecesDiscount: 根据商品类目规则传入, int类型
     * 
     * @ApiParam(value = "分类id", required = true) @RequestBody Long cateId,
     * @ApiParam(value = "国家id", required = true) @RequestBody Integer countryId,
     * @ApiParam(value = "运费模板id", required = true) @RequestBody Long logisticsTemplateId,
     * @ApiParam(value = "商品类型id", required = true) @RequestBody Integer goodsType,
     * @ApiParam(value = "商品id", required = true) @RequestBody Long goodsId,
     * @ApiParam(value = "保税仓", required = true) @RequestBody String warehouse,
     * @ApiParam(value = "满两件折扣", required = true) @RequestBody Integer twoPiecesDiscount
     * @author daigb
     * @date:  2022-11-28 16:37
     */
    @ApiOperation(value = "商品推送")
    @PostMapping("/goodsPush")
    public CommonResult<Object> goodsPush(@Validated @RequestBody SyPddGoodsAddRequest syPddGoodsAddRequest, HttpServletRequest request) throws Exception{
    	return CommonResult.success(pddAccountService.goodsPush(syPddGoodsAddRequest, getMerId(request)));
    }
    
}



